package procTest;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

import proc.BasicFileWrap;
import proc.FileWrap;

public class BasicFileWrapTest {
	
	
	
	private File report;
	private File result;
	private final String path = "src/procTest/IOFiles/";

	@Before
	public void setUp(){
		report = new File(path+"report_output");
		result = new File(path+"result_output");
		report.delete();
		result.delete();
	}
	
	
	private FileWrap fileWrapTest;

	/**
	 * The NO. of args is less than 4
	 */
	@Test
	public void priExistenceTest1() {
		String[] fileNames = { path+"primary_input", path+"auxiliary_input",
				path+"result_output" };
		try {
			this.fileWrapTest = new BasicFileWrap(fileNames);
			fail("No exception thrown!");
		} catch (IllegalArgumentException e) {
			// test passed
		}
	}	
	/**
	 * The NO. of args is larger than 4
	 */
	@Test
	public void priExistenceTest2() {
		String[] fileNames = { path+"primary_input", path+"auxiliary_input",
				path+"result_output", path+"report_output", path+"extra_file" };
		try {
			this.fileWrapTest = new BasicFileWrap(fileNames);
			fail("No exception thrown!");
		} catch (IllegalArgumentException e) {
			// test passed
		}
	}
	/**
	 * The name of the primary input is misspelled
	 */
	@Test
	public void priExistenceTest3() throws IllegalArgumentException {
		String[] fileNames = { path+"wrong name", path+"auxiliary_input",
				path+"result_output", path+"report_output" };
		this.fileWrapTest = new BasicFileWrap(fileNames);
		assertEquals("Error doesn't recognized.", false,
				this.fileWrapTest.checkFiles());
	}
	/**
	 * The primary input exists but No permission
	 */
	@Test
	public void priPmsTest() throws IllegalArgumentException {
		String[] fileNames = { path+"primary_input_no_pms", path+"auxiliary_input",
				path+"result_output", path+"report_output" };
		this.fileWrapTest = new BasicFileWrap(fileNames);
		assertEquals("Error doesn't recognized.", false,
				this.fileWrapTest.checkFiles());
	}
	/**
	 * The primary file name is a directory
	 */
	@Test
	public void priDirTest() throws IllegalArgumentException {
		String[] fileNames = { path, path+"auxiliary_input", path+"result_output",
				path+"report_output" };
		this.fileWrapTest = new BasicFileWrap(fileNames);
		assertEquals("Error doesn't recognized.", false,
				this.fileWrapTest.checkFiles());
	}
	/**
	 * The primary file is valid and extremely large
	 */
	@Test
	public void priExtTest() {
		String[] fileNames = { path+"primary_input_extreme", path+"auxiliary_input",
				path+"result_output", path+"report_output" };
		this.fileWrapTest = new BasicFileWrap(fileNames);
		assertEquals("Large primary file is not able to get processed.", true,
				this.fileWrapTest.checkFiles());

	}
	/**
	 * The name of the aux input is misspelled
	 */
	@Test
	public void auxNameTest() throws IllegalArgumentException {
		String[] fileNames = { path+"primary_input", path+"wrong name",
				path+"result_output", path+"report_output" };
		this.fileWrapTest = new BasicFileWrap(fileNames);
		assertEquals("Error doesn't recognized.", false,
				this.fileWrapTest.checkFiles());
	}
	/**
	 * The auxiliary input file exists but No permission
	 */
	@Test
	public void auxPmsTest() throws IllegalArgumentException {
		// String[] fileNames = { path+"primary_input", path+"auxiliary_input_no_pms",
		// path+"result_output", path+"report_output" };
		File aux = new File(path+"auxiliary_input_no_pms");
		aux.setExecutable(false);
		assertEquals("shit!", false, aux.canRead());
		// this.fileWrapTest = new BasicFileWrap(fileNames);
		// assertEquals("Error is not recognized.", false,
		// this.fileWrapTest.checkFiles());
	}
	/**
	 * The aux file name is a directory
	 * 
	 * @throws IOException
	 */
	@Test
	public void auxDirTest() throws IllegalArgumentException {
		String[] fileNames = { path+"primary_input", path, path+"result_output",
				path+"report_output" };
		this.fileWrapTest = new BasicFileWrap(fileNames);
		assertEquals("Error doesn't recognized.", false,
				this.fileWrapTest.checkFiles());
	}




}
